$(function() {
	//修改平台密码的controller URL
	var url = '/local/changelocalpwd';
    //从地址栏的URL里获取usertype
    //usertype=1则为customer,其余为shopowner
    var usertype=getQueryString("usertype");
	$('#submit').click(function() {
		//获取账号
		var username = $('#username').val();
		//获取原密码
		var password = $('#password').val();
		//获取新密码
		var newPassword = $('#newPassword').val();
		var confirmPassword = $('#confirmPassword').val();
		if (newPassword !=confirmPassword){
			$.toast('两次输入的新密码不一致!');
			return;
		}
		//添加表单数据
		var formData = new FormData();
		formData.append('username', username);
		formData.append('password', password);
		formData.append('newPassword', newPassword);
		//获取验证码
		var verifyCodeActual = $('#j_captcha').val();
		if (!verifyCodeActual) {
			$.toast('请输入验证码！');
			return;
		}
		formData.append("verifyCodeActual", verifyCodeActual);
		//将参数post到后台去修改密码
		$.ajax({
			url : url,
			type : 'POST',
			data : formData,
			contentType : false,
			processData : false,
			cache : false,
			success : function(data) {
				if (data.success) {
					$.toast('提交成功！');
					if (usertype ==1){
						//若用户在前端展示系统页面则自动链接到前端展示系统首页
						window.location.href = '/frontend/index'
					}else {
                        //若用户是在店家管理系统页面则自动链接到店铺列表页面
                        window.location.href = '/shopAdmin/shoplist';
					}
				} else {
					$.toast('提交失败！'+data.errMsg);
					$('#captcha_img').click();
				}
			}
		});
	});

	$('#back').click(function() {
		window.location.href = '/local/login';
	});
});
